package com.cans.ssoserver.util;

import com.cans.base.model.SsoUser;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cans
 * @date 2018/6/21
 * @description 模拟存储票据
 */
public class TicketUtils {

    private static Map<String,SsoUser> ticketMap = new HashMap<>();

    /**
     * 根据ticket获取用户信息
     * @param ticket
     * @return
     */
    public static SsoUser getTicket(String ticket){
        return ticketMap.get(ticket);
    }

    /**
     * 添加票据
     * @param ssoUser
     */
    public synchronized static void putTicket(SsoUser ssoUser){
        ssoUser.setPassword(null);
        ticketMap.put(ssoUser.getUsername(),ssoUser);
    }

    /**
     * 删除票据
     * @param ticket
     */
    public synchronized static void removeTicket(String ticket){
        ticketMap.remove(ticket);
    }
}
